<?
function basket($var,$names)
{
    if(empty($var))return false;
    foreach($var as $i=>$y)
    {
        echo $names[$i].' заказано '.$y.' штук<br/>';
    }
}
class Logger
{
   private $db;
   public function __construct($connection)
   {
       $this->db=$connection;
   }
   public function setLogRecord($msg,$time,$component='none')
   {
       $query="Insert Into `logs` (msg,time,component) Values('$msg','$time','$component')";
       if(!$this->db->query($query))
       {
           throw new Exception($this->db->error);
       }

   }
   public function getLogRecord()
   {
       throw new Exception('Пока не реализовано');
   }
}

class Entries
{
   private $db;
   public function __construct($connection)
   {
       $this->db=$connection;
   }
   public function getEntries($number=10,$start=0)
   {
       $this->db->next_result();
       $query="Select * from entries limit $start,$number";
       if(!$this->db->multi_query($query))
       {
           throw new Exception($this->db->error);
       }
       $result=$this->db->store_result();
       while ($row = $result->fetch_assoc())
            {
                $entries[]=$row;
            }
       return $entries;
   }
      public function getEntriesNames()
   {
       $this->db->next_result();
       $query="Select id,name from entries";
       if(!$this->db->multi_query($query))
       {
           throw new Exception($this->db->error);
       }
       $result=$this->db->store_result();
       while ($row = $result->fetch_assoc())
            {
                $entries[$row[id]]=$row[name];
            }
       return $entries;
   }
   public function updateEntries($id)
   {
       $this->db->next_result();
       $query="Select * from entries limit $start,$number";
       if(!$this->db->multi_query($query))
       {
           throw new Exception($this->db->error);
       }
       $result=$this->db->store_result();
       while ($row = $result->fetch_assoc())
            {
                $entries[]=$row;
            }
       return $entries;
   }
   public function deleteEntries($number=10,$start=0)
   {
       $this->db->next_result();
       $query="Select * from entries limit $start,$number";
       if(!$this->db->multi_query($query))
       {
           throw new Exception($this->db->error);
       }
       $result=$this->db->store_result();
       while ($row = $result->fetch_assoc())
            {
                $entries[]=$row;
            }
       return $entries;
   }
}

class Entry
{

}

class Orders
{
   private $db;
   public function __construct($connection)
   {
       $this->db=$connection;
   }
   public function getEntries($number=10,$start=0)
   {
       $this->db->next_result();
       $query="Select * from orders limit $start,$number";
       if(!$this->db->multi_query($query))
       {
           throw new Exception($this->db->error);
       }
       $result=$this->db->store_result();
       while ($row = $result->fetch_assoc())
            {
                $entries[]=$row;
            }
       return $entries;
   }
}

class Order
{
    private $id;
    private $name;
    private $adress;
    private $phone;
    private $ids;

    public function __construct($id='', $name='', $adress='', $phone='', $ids=array())
    {
        $this->id = $id;
        $this->name = $name;
        $this->adress = $adress;
        $this->phone = $phone;
        $this->ids = $ids;
    }
    public function getId()
    {
        return $this->id;
    }
    public function getName()
    {
        return $this->name;
    }
    public function getAdress()
    {
        return $this->adress;
    }
    public function getPhone()
    {
        return $this->phone;
    }
    public function getIds()
    {
        return $this->ids;
    }

    public function setId($var)
    {
        $this->id=$var;
    }
    public function setName($var)
    {
        $this->name=$var;
    }
    public function setAdress($var)
    {
        $this->adress=$var;
    }
    public function setPhone($var)
    {
        $this->phone=$var;
    }
    public function setIds($var)
    {
        $this->ids=$var;
    }
}
?>
